﻿using Furion.DataEncryption;
using System.Collections.Generic;

using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;

namespace Purchasing.Application
{
    /// <summary>
    /// 系统服务接口
    /// </summary>
    public class SystemAppService : IDynamicApiController
    {
        private readonly ISystemService _systemService;
        public SystemAppService(ISystemService systemService)
        {
            _systemService = systemService;
        }

        /// <summary>
        /// 获取系统描述
        /// </summary>
        /// <returns></returns>
        //[Authorize]
        public string GetDescription()
        {
            return _systemService.GetDescription();
        }
        [AllowAnonymous]
        public string GetAccessToken()
        {
            // 生成 token
            var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>()
            {
                { "UserId", 10001 },  // 存储Id
                { "Account","luo-f" }, // 存储用户名
            });

            // 获取刷新 token
            var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 30); // 第二个参数是刷新 token 的有效期，默认三十天


            return accessToken;
        }
    }
}
